package com.Register.controller.admin;

import com.Register.dto.AdminSkillDocumentPageQueryDTO;
import com.Register.dto.SkillDocumentCreateDTO;
import com.Register.dto.SkillDocumentUpdateDTO;
import com.Register.entity.SkillDocument;
import com.Register.result.PageResult;
import com.Register.result.Result;
import com.Register.service.SkillDocumentService;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

@RestController("webDocumentController")
@RequestMapping("/web/admin/skill")
@Tag(name = "管理员端-技能培训接口")
@Slf4j
public class SkillDocumentController {
    @Resource
    private SkillDocumentService skillDocumentService;

    /*
    创建技能培训文章
     */
    @PostMapping("/create")
    @Operation(summary = "创建技能培训文章")
    public Result<String> createSkillDocument(@RequestBody SkillDocumentCreateDTO skillDocumentDTO) throws JsonProcessingException{
        return skillDocumentService.createSkillDocument(skillDocumentDTO);
    }

    /*
    管理员分页查询所有文章
     */
    @GetMapping("/getAll")
    @Operation(summary = "管理员分页查询所有的文章")
    public Result<PageResult> getAllSkillDocument(@ParameterObject AdminSkillDocumentPageQueryDTO adminSkillDocumentPageQueryDTO){
        return Result.success(skillDocumentService.getAllSkillDocument(adminSkillDocumentPageQueryDTO));
    }

    /*
    管理员更新技能培训文档
     */
    @PutMapping("/update")
    @Operation(summary = "管理员更新技能培训文档")
    public Result<String> updateSkillDocument(@RequestBody SkillDocumentUpdateDTO skillDocumentUpdateDTO){
        return skillDocumentService.updateSkillDocument(skillDocumentUpdateDTO);
    }

    /*
    根据id查询文章
     */
    @GetMapping("/{id}")
    @Operation(summary = "根据id查询文章")
    public Result<SkillDocument> getDocumentByid(@PathVariable("id") String id){
        return Result.success(skillDocumentService.getDocumentByid(id));
    }
}
